package com.supermap.qdsearch.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.supermap.android.maps.CoordinateReferenceSystem;
import com.supermap.android.maps.LayerView;
import com.supermap.android.maps.MapController;
import com.supermap.android.maps.MapView;
import com.supermap.android.maps.Point2D;
import com.supermap.qdsearch.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class ViewFragment extends Fragment {



    @BindView(R.id.map_view)
    MapView mapView;
    Unbinder unbinder;

    private String rest;
    private CoordinateReferenceSystem crs;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_view, container, false);
        unbinder = ButterKnife.bind(this, view);

        rest = getResources().getString(R.string.map_rest_url);

        initMap();

        return view;
    }


    /**
     * 初始化地图
     */
    private void initMap() {
        crs = new CoordinateReferenceSystem();
        crs.wkid = 4326;
        addFristLayer();
    }


    public void addFristLayer() {
        mapView.removeAllLayers();
        LayerView restView = new LayerView(getContext());
        restView.setURL(rest);
        restView.setCRS(crs);
        mapView.addLayer(restView);
        Point2D point2D = new Point2D(118.603243, 37.775859);
        MapController controller = mapView.getController();
        controller.setCenter(point2D);
        controller.setZoom(4);
        //启用内置的缩放控件
        mapView.setBuiltInZoomControls(true);
        mapView.setClickable(true);
        mapView.invalidate();
    }




    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

}
